<?php
namespace Qy {
    /**
    * 企业微信应用管理类
    * @author Jamers
    * @since 2017.1.1
    * @see http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%BA%94%E7%94%A8
    */
    class Agent {
        private $common;
        
        public function __construct($ary = array()) {
            if (isset($ary['common'])) {
                $this->common = &$ary['common'];
            }else{
                $this->common = new \Qy\Common();
            }
        }
        /**
        * 获取企业号某个应用的基本信息
        * @see http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%BA%94%E7%94%A8
        * 
        * @param mixed $agentid
        * @param AccessToken $a_token
        */
        public function getAgentByID($agentid,$a_token='') {
            if (empty($a_token)) $a_token = $this->common->read_access_token();
            $url = "https://qyapi.weixin.qq.com/cgi-bin/agent/get?access_token={$a_token}&agentid={$agentid}";
            return $this->common->httpRequest($url);
        }
        
        /**
        * 设置企业号应用
        * @see http://qydev.weixin.qq.com/wiki/index.php?title=%E8%AE%BE%E7%BD%AE%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%BA%94%E7%94%A8
        * 
        * @param mixed $ary
        * @param mixed $a_token
        */
        public function setAgent($ary,$a_token='') {
            if (empty($a_token)) $a_token = $this->common->read_access_token();
            $url = "https://qyapi.weixin.qq.com/cgi-bin/agent/set?access_token={$a_token}";
            return $this->common->httpRequest($url,$ary,'post');
        }
        
        /**
        * 获取企业号应用列表
        * @see http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E5%BA%94%E7%94%A8%E6%A6%82%E5%86%B5%E5%88%97%E8%A1%A8
        * 
        * @param AccessToken $a_token
        */
        public function getAgentList($a_token='') {
            if (empty($a_token)) $a_token = $this->common->read_access_token();
            $url = "https://qyapi.weixin.qq.com/cgi-bin/agent/list?access_token={$a_token}";
            return $this->common->httpRequest($url);
        }
    }
}
?>
